<html><head><title>Prototypes</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="5">Prototypes</font></b></p>

<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#3A3966">Prototype</font></b>.&lt;type&gt; name(&lt;parameter&gt;, [, &lt;parameter&gt; [= DefaultValue]...])
</font></pre></blockquote>
<b>Description</b><br><blockquote>


For advanced programmers. <b><font color="#3A3966">Prototype</font></b> allows to declare a type which will map 
a function. It's useful when used with a variable, to do a function pointer (the 
variable value will be the address the function to call, and can be changed at will). 
<br>
<br>
This feature can replace the <a href="../library/openlibrary.html">OpenLibrary()</a> and 
<a href="../library/callfunction.html">CallFunction()</a> sequence as it has some 
advantages: type checking is done, number of of parameters is validated. 
<br>
<br>
Unlike CallFunction(), it can deal with double, float and quad <a href="variables.html">variables</a> 
without any problem. To get easily the pointer 
of a library function, use <a href="../library/getfunction.html">GetFunction()</a>. 
<br>
<br>
The last parameters can have a default value (need to be a constant expression), so if 
these parameters are omitted when the function is called, the default value will be used. 
<br>
<br>
By default the function will use the standard call convention (stdcall on x86, or fastcall on x64). If the function pointer will be 
a C one, the <b><font color="#3A3966">PrototypeC</font></b> variant should be used instead. 
<br>
<br>
The <a href="pseudotypes.html">pseudotypes</a> can be used for the parameters, but not for the returned 
value. 

</blockquote><p><b>Example</b></p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">
  <b><font color="#3A3966">Prototype</font></b>.i <font color="#3A3966">ProtoMessageBox</font>(Window.i, Body$, Title$, Flags.i = 0)

  <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenLibrary</font>(0, &quot;User32.dll&quot;)
   
    <font color="#3A3966">; 'MsgBox' is a variable with a 'ProtoMessageBox' type</font>
    <font color="#3A3966">;</font>
    MsgBox.ProtoMessageBox =<font color="#3A3966"> GetFunction</font>(0, &quot;MessageBoxA&quot;)
    
<font color="#3A3966">    MsgBox</font>(0, &quot;Hello&quot;, &quot;World&quot;) <font color="#3A3966">; We don't specify the flags</font>
  <b><font color="#3A3966">EndIf</font></b>
    
</font></pre>


</blockquote><p><b>Example:</b> With pseudotypes</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; We use the 'p-unicode' pseudotype for the string parameters, as</font>
  <font color="#3A3966">; MessageBoxW() is an unicode only function. The compiler will </font>
  <font color="#3A3966">; automatically converts the strings to unicode when needed.</font>
  <font color="#3A3966">;</font>
  <b><font color="#3A3966">Prototype</font></b>.i <font color="#3A3966">ProtoMessageBoxW</font>(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)

  <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenLibrary</font>(0, &quot;User32.dll&quot;)
   
    <font color="#3A3966">; 'MsgBox' is a variable with a 'ProtoMessageBoxW' type</font>
    <font color="#3A3966">;</font>
    MsgBox.ProtoMessageBoxW =<font color="#3A3966"> GetFunction</font>(0, &quot;MessageBoxW&quot;)
    
<font color="#3A3966">    MsgBox</font>(0, &quot;Hello&quot;, &quot;World&quot;) <font color="#3A3966">; We don't specify the flags</font>
  <b><font color="#3A3966">EndIf</font></b>
    
</font></pre>



</body></html>